public class demo2 {
    public static void main(String[] args) {
        Object object = new Object();
        Thread t1 = new Thread(() -> {
            //会出现非法监视器状态异常，原因是因为没有加锁，wait能够实现的条件之一就是要有锁
                System.out.println("wait之前");
                try {
                    object.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("wait之后");
        });

        Thread t2 = new Thread(() -> {
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("发送通知");
                object.notify();
        });
        t1.start();
        t2.start();
    }

}
